package com.jack.payment.constant.enums;

import com.jack.payment.entity.common.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public enum AccountVerifyCodeEnum {
    REGISTER(0, "jack:payment:account:register:",
            "official_register", "basic_verify_email"),       // 注册
    FORGET_PWD(1, "jack:payment:account:forget:",
            "official_forget", "basic_verify_email"),         // 忘记密码
    BINDING(2, "jack:payment:account:binding:",
            "official_binding", "basic_verify_email"),        // 判定
    VERIFY(3, "jack:payment:account:verify:",
            "official_verify", "basic_verify_email"),         // 账号验证
    ;

    private static Logger log = LoggerFactory.getLogger(AccountVerifyCodeEnum.class);

    private Integer type;

    private String redisKey;

    private String subject;

    private String text;

    public Integer getType() {
        return type;
    }

    public String getRedisKey() {
        return redisKey;
    }

    public String getSubject() {
        return subject;
    }

    public String getText() {
        return text;
    }

    AccountVerifyCodeEnum(Integer type, String redisKey, String subject, String text) {
        this.type = type;
        this.redisKey = redisKey;
        this.subject = subject;
        this.text = text;
    }

    /**
     * 获取验证码方式
     * @param type       类型
     * @return
     * @throws BusinessException
     */
    public static AccountVerifyCodeEnum getAccountVerifyCodeEnum(Integer type) throws BusinessException {
        if (type != null) {
            for (AccountVerifyCodeEnum verifyCodeEnum : values()) {
                if (type.equals(verifyCodeEnum.getType())) {
                    return verifyCodeEnum;
                }
            }
        }
        log.warn("使用错误的验证 类型==>>>{}", type);
        throw new BusinessException();
    }
}
